package com.lk.springboot.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lk.springboot.service.LoginService;
import com.lk.springboot.service.SitesPhotoService;
import com.lk.springboot.vo.Result;
import com.lk.springboot.vo.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author lk
 * @date 2020/1/10 0010 19:04
 * @description: 站点拼图附加模块
 */
@RestController
public class SitesPhotoController {
    @Autowired
    SitesPhotoService sitesPhotoService;
    @Autowired
    LoginService loginService;

    /**
     * 获取站点拼图(标注了灰/彩)
     *
     * @param token
     * @param s_id
     * @return
     */
    @RequestMapping(value = "/sites", method = RequestMethod.GET)
    public String getPhotos(@CookieValue("token") String token,
                            @RequestParam(value = "s_id", defaultValue = "000000") String s_id) {
        String u_id = loginService.checkID(token);
        if (u_id == null) {
            Result ru = new Result(ResultCode.FAILD_LOGIN);
            ru.setData(" ");
            return JSON.toJSONString(ru);
        } else {
            List sites = sitesPhotoService.getSPOfSites(u_id, s_id);
            Result result = new Result(ResultCode.SUCCESS);
            result.setData(sites);
            return JSON.toJSONString(result);
        }
    }


}
